/*
 * @Author: Collin colin.w.cai@hotmail.com
 * @Date: 2019-07-28 20:50:10
 * @LastEditors: Collin colin.w.cai@hotmail.com
 * @LastEditTime: 2022-10-26 00:02:13
 * @FilePath: /First/Volumes/BC-MAC-COLLIN/Workspace/Programming Training/Go Lang/linn-go-practice/types/pointer.go
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
package types

import "fmt"

func zeroval(ival int) {
	ival = 0
}

func zeroptr(iptr *int) {
	*iptr = 0
}

func DemoPointer() {

	i := 1
	fmt.Println("initial, i is equal to 1, i: ", i) // //i 等于 1

	zeroval(i)
	fmt.Println("After call zeroval func, i is still equal to 1, i: ", i) //i 依旧等于 1

	zeroptr(&i)
	fmt.Println("After call zeroptr func, i changed to 0, i:", i) //i 将变成 0

	zeroptr(&i)
	fmt.Println("Call zeroptr again, i is still equal to 0, i: ", i) //i 将变成 0

	fmt.Println("pointer:", &i) // 将显示指向 i 的地址
}

func DemoPointer1() {
	i := 47483
	j := 0
	var iptr *int = &i
	var iptr1 *int = &j
	fmt.Println("pointer:", iptr, iptr1)
	//*iptr 通过地址访问存储器中的值
	fmt.Println("pointer:", *iptr, *iptr1)
}
